<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>活动管理</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="../vue/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script src="../vue/axios.v0.21.1.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style>
        body{ margin: 0;padding: 0}
        .demo-form-inline{padding-top: 20px;inset-block: auto;float: left}
        .one{padding: 10px;margin-top: 20px;}
        .table{text-align: center;}
        #footer{width:100%;height: 60px;margin-left: 450px;margin-right: 250px;margin: 0 auto}
    </style>
</head>
<body>
<div id="app">

    <el-row>
        <el-col :span="24">
            <div class="filter-container">
                <el-input placeholder="活动名称" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
            </div>
        </el-col>
    </el-row>
    <el-row>
        <el-col :span="24">
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="activityname" label="活动名称" align="center"></el-table-column>
                <el-table-column prop="starttime" label="开始时间" align="center"></el-table-column>
                <el-table-column prop="endtime" label="结束时间" align="center"></el-table-column>
                <el-table-column prop="place" label="地点" align="center"></el-table-column>
                <el-table-column prop="promoter" label="发起人" align="center"></el-table-column>
                <el-table-column prop="shouldnumber" label="邀请人数" align="center"></el-table-column>
                <el-table-column prop="realnumber" label="参与人数" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="danger" @click.once="handleJoin(scope.row)">参加</el-button>
                        <el-button size="mini" type="danger" @click.once="handleNoJoin(scope.row)">不参加</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-col>
    </el-row>
    <div  id="footer">
        <el-row>
            <el-col :span="24">
                <div class="pagination-container">
                    <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>
    </div>
</div>

<script type="text/javascript">
    new Vue({
        el:"#app",
        data:{
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created(){
            this.findPage();
        },
        methods: {
            handleCurrentChange(currentPage) {
                //修改当前页码
                this.pagination.currentPage=currentPage;
                //重新刷新数据
                this.findPage();
            },


            //分页查询
            findPage(){
                //定义后台分页参数
                var param= {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };
                //后台数据库分页查询检查项
                axios.post("/activity-teacher/findByPage",param)
                    .then(res=>{
                        //展示分页数据
                        this.$message.success(res.data.message);
                        this.dataList = res.data.data.rows;
                        this.pagination.total=res.data.data.total;
                    })
            },

            //参加活动
            handleJoin(row){
                this.$confirm('确定要参加活动吗?', '参加提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //执行后台的删除操作
                    var join='B';
                    axios.post("/activity-teacher/joinActivity?id="+row.id+"&join="+join).then(res=>{
                        if (res.data.flag){
                            this.$message.success(res.data.message);
                        } else {
                            this.$message.error(res.data.message);
                        }
                        var that=this;
                        window.setTimeout(function () {
                            that.findPage();
                        },2000)
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //不参加活动
            handleNoJoin(row){
                this.$confirm('确定不参加活动吗?', '不参加提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //执行后台的删除操作
                        var join = 'C';
                        axios.post("/activity-teacher/joinActivity?id="+row.id+"&join="+join).then(res=>{
                            if (res.data.flag){
                                this.$message.success(res.data.message);
                            } else {
                                this.$message.error(res.data.message);
                            }
                            var that=this;
                            window.setTimeout(function () {
                                that.findPage();
                            },2000)
                        });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    })
</script>

</body>
</html>